
package Hoja07;

public class HeapClass<T> {
    private int tope;
    private Nodo[] cosos;
    private int amount;

    public HeapClass(int tope) {
        this.tope = tope;
        cosos =  new Nodo[tope];
        amount = 0;
    }

    public void insert(Nodo coso) {
        int j;

        if(amount == 0)
            cosos[amount++] = coso;
        else {
            for(j=amount -1; j>=0; j--) {
                if(coso.getRepet() >= cosos[j].getRepet())
                    cosos[j+1] = cosos[j];
                else
                    break;

            }

            cosos[j+1] = coso;
            amount= amount+1;
        }


    }

    public Nodo remove() {
        amount =amount-1;
        return cosos[amount];
    }


    public Nodo remove(Nodo nodo) {
        Nodo temp;
        for(int i =0; i < amount; i++) {
            if(cosos[i].getDato().toString().charAt(0) == nodo.getDato().toString().charAt(0)) {
                temp = cosos[i];
                cosos[i] = null;
                for(int j = i+1; j < amount; j++)
                    cosos[i] = cosos[j];
                amount =amount -1;
                return temp;
            } 
               

        }
  
        return null;
    }



    public Nodo seeFirst() {

        return cosos[amount-1];

    }

  

    public int getAmount() {
        return amount;
    }

    public Nodo getNodo(Nodo nodo) {
        for(int i =0; i < amount; i++) {
            if(cosos[i].getDato().toString().charAt(0) == nodo.getDato().toString().charAt(0)) {
                return cosos[i];
            }
        }
        return null;
    }
}
